/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>评价管理</h3>
        <h5>商品交易评价管理</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>买家可在订单完成后对订单商品进行评价操作，评价信息将显示在对应的商品页面</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>商品评价列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div @click="removeBatch()" class="add">
          <span>
            <i class="el-icon-remove" /> 批量删除
          </span>
        </div>
      </div>
      <div class="fbutton">
        <div @click="updateBatch(1)" class="add">
          <span>
            <i class="fa fa-eye" /> 显示
          </span>
        </div>
      </div>
      <div class="fbutton">
        <div @click="updateBatch(0)" class="add">
          <span>
            <i class="el-icon-view" /> 隐藏
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input
          class="searchinput"
          v-model="content"
          width="10"
          size="small"
          placeholder="评论内容"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="username"
          width="10"
          size="small"
          placeholder="搜索用户"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="用户" prop="nickname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="评分" prop="goods_rank" width="160">
          <template scope="scope">
            <el-rate v-model="scope.row.goods_rank" void-color="#C6D1DE" disabled></el-rate>
          </template>
        </el-table-column>
        <el-table-column label="评论内容" prop="content" width="120"></el-table-column>
        <el-table-column label="晒单图片" width="120">
          <template scope="scope">
            <img :src="scope.row.img" width="40" height="30" />
          </template>
        </el-table-column>
        <el-table-column label="商品" prop="goods_name" width="260"></el-table-column>
        <el-table-column label="显示" width="80">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.is_show"
              @change="update(scope.row.comment_id,scope.row.is_show)"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="评论时间" prop="add_time_format" width="180"></el-table-column>
        <el-table-column label="ip地址" prop="ip_address" width="120"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" icon="el-icon-delete" @click="remove(scope.row.comment_id)">删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getCommentPage,
  updateCommentsIsShow,
  deleteComments
} from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      username: null,
      content: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getCommentPage({
        content: that.content,
        username: that.username,
        page: that.currentPage,
        size: that.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    updateBatch(is_show) {
      //获取选中的记录
      var rows = this.$refs.multipleTable.selection;
      var ids = [];
      rows.forEach(e => {
        ids.push(e.comment_id);
      });
      if (ids.length == 0) {
        this.$message.info("请选择需要修改的记录!");
        return;
      }
      this.update(ids, is_show);
    },
    update(ids, is_show) {
      var that = this;
      updateCommentsIsShow(ids, is_show).then(function(res) {
        if (res.status == 1) {
          that.getPage();
          that.$message.success("操作成功!");
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    removeBatch() {
      //获取选中的记录
      var rows = this.$refs.multipleTable.selection;
      var ids = [];
      rows.forEach(e => {
        ids.push(e.comment_id);
      });
      if (ids.length == 0) {
        this.$message.info("请选择需要删除的记录!");
        return;
      }
      this.remove(ids);
    },
    remove(ids) {
      var that = this;
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteComments(ids).then(function(res) {
            if (res.status == 1) {
              that.getPage();
              that.$message.success("删除成功!");
            } else {
              that.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          that.$message.info("已取消删除");
        });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
